/**
 * 
 */
package com.dfhc.bus.addressbook;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.quickbundle.base.web.page.RmPageVo;
import org.quickbundle.tools.helper.RmJspHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.alibaba.fastjson.JSONObject;
import com.dfhc.ISystemConstant;
import com.dfhc.bus.generalservice.service.GeneralServiceService;
import com.dfhc.bus.generalservice.vo.GeneralServiceVo;
import com.dfhc.pub.service.ExtGeneralService;

/**
 * @author longsebo
 * 通讯录扩展服务
 */
@Service("com.dfhc.bus.addressbook.AddressBookService")
public class AddressBookService extends ExtGeneralService {
	@Autowired
	GeneralServiceService generalServiceService; 
	@Override
	public Map<String, Object> doAjaxInsert(HttpServletRequest request,
			GeneralServiceVo vo) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> doAjaxUpdate(HttpServletRequest request,
			GeneralServiceVo vo) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> ajaxGet(String id, String businessTableName,
			HttpServletRequest request) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String delete(HttpServletRequest request,
			RedirectAttributes redirectAttributes) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> doAjaxDelete(HttpServletRequest request) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String doLogicDelete(HttpServletRequest request,
			RedirectAttributes redirectAttributes) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String detail(String id, Model model, HttpServletRequest request) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void exportXls(Model model, HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void importXls(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void ajaxList(Model model, HttpServletRequest request,HttpServletResponse response) throws IOException  {
		Map<String,Object> dataMap=new HashMap<String,Object>();
        
        String page=request.getParameter("page")==null?"1":request.getParameter("page");
        String rows=request.getParameter("rows")==null?ISystemConstant.DEFAULT_PAGE_SIZE:request.getParameter("rows");
        int rowsInt=Integer.parseInt(rows);//页大小
        int pageInt=Integer.parseInt(page);//当前页
        Map<String, Object> searchPara = getQueryCondition(request);  //从request中获得查询条件
        RmPageVo pageVo = RmJspHelper.transctPageVo(request, generalServiceService.getCount(searchPara));
        pageVo.setPageSize(rowsInt);
        pageVo.setCurrentPage(pageInt);
        String orderStr = RmJspHelper.getOrderStr(request);  //得到排序信息
        
        List<GeneralServiceVo> beans = generalServiceService.list(searchPara, orderStr, pageVo.getStartIndex(), pageVo.getPageSize());  //按条件查询全部,带排序
         
        dataMap.put("page",  pageVo.getCurrentPage());
        dataMap.put("total",  pageVo.getPageCount());
        dataMap.put("records",  pageVo.getRecordCount());
        dataMap.put("rows", beans);
         
        response.setCharacterEncoding("UTF-8"); 
        response.getWriter().write(JSONObject.toJSONString(dataMap));
	}
}
